//
//  C-2-ViewController.m
//  页面之间传值
//
//  Created by MAC on 2018/8/28.
//  Copyright © 2018年 MAC. All rights reserved.
//

#import "C-2-ViewController.h"

@interface C_2_ViewController ()
//声明全局UI指针
@property (nonatomic,strong) UITextField *textF;
@property (nonatomic,strong) UIButton *btn;
@end

@implementation C_2_ViewController
//UITextField的懒加载
- (UITextField *)textF
{
    if (_textF == nil) {
        _textF = [[UITextField alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 100, 200, 40)];
        _textF.textColor = [UIColor blackColor];
        _textF.borderStyle = UITextBorderStyleLine;
    }
    return _textF;
}
//UIButton的懒加载
- (UIButton *)btn
{
    if (_btn == nil) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn.backgroundColor = [UIColor redColor];
        _btn.frame = CGRectMake((self.view.frame.size.width-200)/2, _textF.frame.origin.y+_textF.frame.size.height+40, 200, 40);
        [_btn setTitle:@"跳转页面一" forState:UIControlStateNormal];
        [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn.titleLabel.font = [UIFont systemFontOfSize:20];
        
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //把UI指针添加到View视图中
    [self.view addSubview:self.textF];
    [self.view addSubview:self.btn];
}

//返回A页面
- (void)btnClick
{
    //把想要传递的值写入文件中
    [[NSUserDefaults standardUserDefaults] setObject:self.textF.text forKey:@"NSUserDefaults-re"];
    //接着要把NSUserDefaults同步一下
    [[NSUserDefaults standardUserDefaults]synchronize];
    //返回A页面
    [self.navigationController popViewControllerAnimated:YES];
}



@end
